package com.remark.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    
    // 定义交换机名称
    public static final String VOUCHER_ORDER_EXCHANGE = "voucher.order.exchange";
    // 定义队列名称
    public static final String VOUCHER_ORDER_QUEUE = "voucher.order.queue";
    // 定义routingKey
    public static final String VOUCHER_ORDER_ROUTING_KEY = "voucher.order";
    
    // 声明交换机
    @Bean
    public DirectExchange voucherOrderExchange() {
        return new DirectExchange(VOUCHER_ORDER_EXCHANGE);
    }
    
    // 声明队列
    @Bean
    public Queue voucherOrderQueue() {
        return QueueBuilder.durable(VOUCHER_ORDER_QUEUE).build();
    }
    
    // 绑定交换机和队列
    @Bean
    public Binding voucherOrderBinding() {
        return BindingBuilder
                .bind(voucherOrderQueue())
                .to(voucherOrderExchange())
                .with(VOUCHER_ORDER_ROUTING_KEY);
    }
} 